package com.loie.datacenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.loie.datacenter.comm.CommJSON;
import com.loie.datacenter.config.DgMVCProperties;
import com.loie.datacenter.mapper.CustomerItemsMapper;
import com.loie.datacenter.model.CustomerItems;
import com.loie.datacenter.model.ProdInfo;
import com.loie.datacenter.model.Shipments;
import com.loie.datacenter.model.bo.LoginBO;
import com.loie.datacenter.model.bo.ParamBO;
import com.loie.datacenter.model.bo.UserListBO;
import com.loie.datacenter.service.CustomerItemsService;
import com.loie.datacenter.service.ProdInfoService;
import com.loie.datacenter.service.SysApiService;
import com.loie.datacenter.service.UserListService;
import com.loie.datacenter.util.FiledownUtil;
import com.loie.datacenter.util.RsaUtil;
import com.loie.datacenter.util.SecureUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@MapperScan("com.loie.datacenter.mapper")


public
class Usertest {
   @Autowired
   private UserListService userListService;
    @Autowired
    private  RedisTemplate<String, String> redisTemplate;
    @Autowired
    private  SysApiService sysApiService;
    @Autowired
    private
    CustomerItemsMapper customerItemsMapper;


    @Autowired
    DgMVCProperties wxMVCProperties;

    @Autowired

    private CustomerItemsService customerItemsService;

    @Autowired
    private ProdInfoService prodInfoService;
    final static String SLAT = "loie_api";

    @Test
    public void test_transferpngtojpg() throws IOException {
        String filepath="d:\\67484353c41d2de02f4b9fa1.png";
        String destfilepath="d:\\67484353c41d2de02f4b9fa1.jpg";
        FiledownUtil.convertPngToJpg(new File(filepath),  new File(destfilepath),0.95f);
    }


    @Test
    public void test_polylinkpro() throws Exception {

        QueryWrapper<ProdInfo> wrapper = new QueryWrapper();
        wrapper.eq("Status",  "normal")        // 状态过滤
                .in("busi_group_id",            // 业务组ID集合
                        "66f1161366e586a72e71beda",
                        "6124494cdd591d7eb7686968"
                )
                .orderByDesc("create_date")     // 按创建时间倒序
                .last("LIMIT 20");                       // 限制结果数量

// 执行查询获取List集合
        List<ProdInfo> prodInfoList = prodInfoService.list(wrapper);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", prodInfoList);
        CommJSON commJson = new CommJSON();
        commJson.setData(jsonObject);
        //System.out.println(commJson);
        for (int i = 0; i < prodInfoList.size(); i++) {
            ProdInfo prodInfo=prodInfoList.get(i);
            System.out.println(String.format("polylink产品第%d个/共%d个:产品编号：%s,品名：%s正在导入",i+1,prodInfoList.size(),prodInfo.getProdId(),
                    prodInfo.getProdName()));
            CustomerItems customerItems=new  CustomerItems();
            QueryWrapper itemquery=new QueryWrapper();
            itemquery.eq("khbz", prodInfo.getProdId());
            int count=customerItemsService.count(itemquery);
            if (count==0){
                customerItems.setRecordID(UUID.randomUUID().toString().toUpperCase());

                customerItems.setCreated(new Date());
                customerItems.setLastModified(new Date());
                //if (StringUtils.isNotBlank(prodInfo.getProdName()))
                customerItems.setCHNItemName(prodInfo.getProdName()!= null ? prodInfo.getProdName()  : customerItems.getCHNItemName());//中文品名
                customerItems.setENGItemName(prodInfo.getProdNameEn()!= null?prodInfo.getProdNameEn():customerItems.getENGItemName());//英文文品名
                //if (StringUtils.isNotBlank(prodInfo.getProdMaterial()))
                customerItems.setCpcz(prodInfo.getProdMaterial()!= null?prodInfo.getProdMaterial():customerItems.getCpcz());//产品材质中
                //if (StringUtils.isNotBlank(prodInfo.getProdMaterialEn()))
                customerItems.setMaterial(prodInfo.getProdMaterialEn()!=null?prodInfo.getProdMaterialEn():customerItems.getMaterial());//产品材质英
               // if (prodInfo.getFobPrice()!=null)
                customerItems.setSalesPrice(prodInfo.getFobPrice()!=null?prodInfo.getFobPrice().doubleValue():0);

                customerItems.setCustomerItemNO(prodInfo.getProdId()!=null?prodInfo.getProdId():customerItems.getCustomerItemNO());
                customerItems.setCustomerNo(prodInfo.getComId()!=null?prodInfo.getComId():customerItems.getCustomerNo());
                //else
                  //  customerItems.setSalesPrice(0.0);
//                String filepath="D:\\001.jpg";
                if (StringUtils.isNotBlank(prodInfo.getMainPic())){
                String ext = FilenameUtils.getExtension(prodInfo.getMainPic());

                byte[] photo=FiledownUtil.toByteArray(prodInfo.getMainPic());
                if (ext.equals("png"))
                 photo=FiledownUtil.convertPngBytesToJpgBytes(photo,0.9f);
                if(photo!=null){
                    //String filepath="d:\\"+prodInfo.getProdId()+".png";
                //FiledownUtil.convertByteArrayToFile(filepath, photo);


                customerItems.setPhoto(photo);}}
                customerItems.setKhbz(prodInfo.getProdId());
                customerItems.setPurchasePrice(prodInfo.getPuPrice()!=null?prodInfo.getPuPrice().doubleValue():0);
                customerItems.setDcptj(0.0);
                //System.out.println(customerItems);
                Boolean savecount=customerItemsService.save(customerItems);
                if (savecount){
                    System.out.println(String.format("polylink产品:产品编号：%s,品名：%s导入成功",prodInfo.getProdId(),
                            prodInfo.getProdName()));
                }



            }


        }
        //System.out.println(prodInfoList);


    }

    @Test
    public void copy_customeritems(){
        QueryWrapper query = new QueryWrapper();
        QueryWrapper querysub = new QueryWrapper();
       // querysub.select("top 10 *");
//        query.gt("shippingdate","2023-01-01");
//        query.le("shippingdate","2023-01-31");
        query.eq("CustomerNo","DE001");
        List<CustomerItems> customerItemsList=customerItemsMapper.selectList(query);
        System.out.println(customerItemsList);

    }


    @Test
    public void password_md5() {
        String password = "123456";
        password = SecureUtil.MD5Encode(password);
        System.out.println(password);
        String comparePasswd = "2024-06-29 20:41:51" + SLAT + password;
        String enComparePasswd = SecureUtil.MD5Encode(comparePasswd);
        System.out.println(enComparePasswd);
        //System.out.println(password);
    }
    @Test
    public void test_config(){
        String configs[]=(wxMVCProperties.getContextInterceptorExcludePathPatterns());
        for (String notifystr : configs) {
            System.out.println(notifystr);

        }

    }
    @Test
    public void create_pub_piv_key() throws Exception {
        String algorithm = "RSA";
        RsaUtil.generateKeyToFile(algorithm, "a.pub", "a.pri");
    }
    @Test
    public void  rasdemo() throws IOException {
        String input = "{ \"billNotifyNo\": \"A03QC1390-001\", \"orderNum\": \"A03QC1390-zjnb969\"}";
        String  priPath="a.pri";
        String privateKeyString = FileUtils.readFileToString(new File(priPath), Charset.defaultCharset());
    }

    @Test
    public void test_login() throws IOException {
        CloseableHttpResponse response1 = null;
        CloseableHttpClient httpclient = HttpClients.createDefault();


        //String url="http://localhost:9200/DataCenter/api/login";
//        String url="http://localhost:8005/service-msm/api/login";
        //String url="http://localhost:8090/QianchengAPI/API/SendToSpdb/ordLndStQry";
        String url="http://localhost:8005/service-msm/api/login";
        JSONObject object = new JSONObject();
        LoginBO bo=new LoginBO();
        bo.setUserName("admin");
        //2023-05-10 23:48:51loie_api25D55AD283AA400AF464C76D713C07AD
        bo.setLoginDate("2024-06-29 20:41:51");
        String password="123456";
        password=SecureUtil.MD5Encode(password);

        String comparePasswd = bo.getLoginDate() + SLAT + password;

        comparePasswd=SecureUtil.MD5Encode(comparePasswd);
        System.out.println(comparePasswd);
        bo.setPassword(comparePasswd);
        String jsonString = JSON.toJSONString(bo);

        System.out.println(jsonString);
        HttpPost httpPost = new HttpPost(url);

        httpPost.setEntity(new StringEntity(jsonString, StandardCharsets.UTF_8));
        //httpPost.setHeader("Content-Type", "application/text;charset=utf8");
        httpPost.setHeader("Content-type", "application/json");


        //httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        response1 = httpclient.execute(httpPost);

        HttpEntity entity = response1.getEntity();
        if (entity != null) {
            //按指定编码转换结果实体为String类型
            String body = EntityUtils.toString(entity, "UTF-8");
            System.out.println(body);

        }


    }

    @Test
    public void setAES() throws Exception {
        CloseableHttpResponse response1 = null;
        CloseableHttpClient httpclient = HttpClients.createDefault();


        //String url="http://localhost:9200/api/setAES";

        String url="http://localhost:8005/service-msm/api/setAES";
        //String url="http://localhost:8090/QianchengAPI/API/SendToSpdb/ordLndStQry";
        JSONObject object = new JSONObject();
        ParamBO bo=new ParamBO();
        String str= UUID.randomUUID().toString().replace("-","");
        System.out.println(str);
        String path = "/key/a.pub";
        Resource resource = new ClassPathResource(path);


        String publickey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCNYPccV49a6Vw8q9RO2ZgqST+x72zZG5XfmUjz\r\n7nwuw0QAMBUfeshMfe8iQuq0oIXXcLTqa7BdNEMcd9n2sYfOeeOOiP9z5wOxfB1Swfu+tqkM7Sme\r\nj0YUH6MMoXLHRwNQXGIekLTM8hn3XNMINU1clkdaVrqPnWevRx5M+8Ct0wIDAQAB\r\n";

                //FileUtils.readFileToString(new File(resource.getURI()), Charset.defaultCharset());
        System.out.println(publickey);
        path = "/key/token.txt";
        resource = new ClassPathResource(path);

        String token=FileUtils.readFileToString(new File(resource.getURI()), Charset.defaultCharset());
        //System.out.println(token);
        //System.exit(0);
        //String publickey="";
        //System.out.println(publickey);
        //System.exit(0);

        String resJiami=RsaUtil.encryptRSA(str, publickey);

        bo.setSecretKey(resJiami);


        String jsonString = JSON.toJSONString(bo);
        System.out.println(jsonString);


        HttpPost httpPost = new HttpPost(url);

        //String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQ2MDg0MDUsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4NDU5MDQwNX0.tfR7sdMv10JadaaIF3LFHMn1i2p4_d35KaFUSfwUZTs";

        httpPost.setEntity(new StringEntity(jsonString, StandardCharsets.UTF_8));

        //String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwMDc0MTQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4Mzk4OTQxNH0._LYWBPBqfBYYpDuJ4d1HQK6dAvavkuLLUhT4sSBeBCc";
        //httpPost.setHeader("Content-Type", "application/text;charset=utf8");
//        httpPost.setHeader("Authorization",token);
        httpPost.setHeader("Authorization",token);
        httpPost.setHeader("Content-type", "application/json");




        //httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        response1 = httpclient.execute(httpPost);
        System.out.println("response1"+response1);

        HttpEntity entity = response1.getEntity();
        if (entity != null) {
            //按指定编码转换结果实体为String类型
            String body = EntityUtils.toString(entity, "UTF-8");
            System.out.println(body);

        }


    }
    @Test public void getprivatekey(){
        String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQ2MDg0MDUsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4NDU5MDQwNX0.tfR7sdMv10JadaaIF3LFHMn1i2p4_d35KaFUSfwUZTs";
        String redisKey = SecureUtil.MD5Encode(String.format("[DataCenter][privateKey][%s]",token));
        System.out.println(redisKey);

    }

    @Test public void getrediskey(){
        String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwODU0ODQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4NDA2NzQ4NH0.KNboMJDQ1dzeDzaRpUJ4TPlvcutQjSzvYkhotw09i4U";
        String redisKey = SecureUtil.MD5Encode(String.format("[DataCenter][secretKey][%s]",token));
        System.out.println(redisKey);

    }
    @Test
    public void AES() throws Exception {
//        String msg="{\"user\":\"\",\"name\":\"\",\"isLocked\":\"\",\"dataAuthority\":\"\",\"roleId\":\"\",\"pageSize\":9,\"pageIndex\":0}";
//         //msg="2knIueI1tjiHYV0aVybYgWzOQOChw+xlKQy1H1+DcPTt+T//TZ2Id+ybYEd4sl2LxAmwx+30I/7MZkp3O6LrG9ExTk9Kp35cpQZ1AcF5hcTMqNjVwqWd/TwLGWxOgaZs";
        String key="f9210027a93d4fc8b90ce8b11ffcd830";
//        //String mwMsg = SecureUtil.decryptAES(msg, key);
//        String mwMsg = SecureUtil.encryptAES(msg, key);
        String mwMsg="RwTTUt2v58BDl6VkO/aid9M7mTbW/8e3esLG1pDaJPYirPZ52ZVtlGqm+agJ3MGyZy4Rc4aaZLxnsRfg+QwjhqVrhTYtkXpcdtLrd1CA7JC2SQ8CDFO/QSiI5MCuf7ApoZA7u/FGWe/T02WjxZeUcrn4HSF4SZNLycJS9lfiirjb9PzEgK57w9d0cj13QsglHyrZZtzMAW6Tcrq2OX9/UGWBc5V9CKh5RoQk6x0b88J34SILgtg2BQ19thL9+UCVAVwCzm2BIG6OnQ818YC5npuufEZjJQF4fjlcfHEhMIma+/alir44pRZ1H37rWBdjBBXEbReemu50/h3c79PeHLH5w8Uht4SMGKVT2Xcz+AavHNPFgWf0ZkgXevxBE8HpfJ6fkjbUird8kXXScYb+aaY4MldZKF/HsX1WSwXaPXNd5bmsJ0aIxvpAKvSv+D/eZEVTio75cx1jt2++Il6y6EMYCx8coSFXExVGTjckNEZunWC+VeYZUIYQC9LU0SBBHyadUN6xtqQiFrciALZCYp2lLYYbXxYhO+y2nYRv4+vHUgmnuVfd1mHo9+NnYz1LgPv0+jnDpcZwbx7Qef/X5vtIjBL7nD9PRGZRC1VXPT+G44pIrUH8Ex89y1ktL/058e5OeR/r6pt5ermE8biTLZPIX9u0aqZvm5NlXsxZNDvJTYYA3i/tn7pd8Fmo63B8GI7Tfq5nfcMKimZhqRooofb42qzcxc2+7Nh27kmVqCrk7QCcspARiVDfVaNx+bzbeBUUR7Nxfo/NqC/uF2QDovGKanOqtm/vbJHdyyPohj5MsLbhSukcg2xdPeNDjjotoqtBQhujQqNFDJTeO3bznH/wN7T8/Geh285TdLTzvofzICADP0hnZOUq4pGP6dUl0OU0OArKm/wun5NkBZamWFohWd1TEIRroWDNA9BQ1wlYEnj1BEgJgmqVtG4Sq/kJ8WFb9C0q7o4OlYitA/sZp1shbPA9x55DXSEcSeyMM+QWTyhLPLaoSAfGxkUJtXO3a1twXMK6kjWWZlqNaUktmNHjCg0WqVK5z0SV9DX4WOc85gjLm2lr/vnGG1UsiQsJmQaUrzUYpBHHuKCH8c90L1Usx5Zn8325/8Q/ZADQdG4=";
        System.out.println(mwMsg);
         mwMsg = SecureUtil.decryptAES(mwMsg, key);
        System.out.println(mwMsg);
    }
    @Test
    public void changepassword() throws Exception {
        CloseableHttpResponse response1 = null;
        CloseableHttpClient httpclient = HttpClients.createDefault();


        //String url="http://localhost:9200/api/setAES";

        String url = "http://localhost:8005/service-msm/api/changePwd";
        //String url="http://localhost:8090/QianchengAPI/API/SendToSpdb/ordLndStQry";
        JSONObject object = new JSONObject();


        HttpPost httpPost = new HttpPost(url);
        String path = "/key/token.txt";
        Resource resource = new ClassPathResource(path);
        String token =FileUtils.readFileToString(new File(resource.getURI()), Charset.defaultCharset());
        LoginBO bo=new LoginBO();

        //loginBO.setPassword("E10ADC3949BA59ABBE56E057F20F883E");
        bo.setCurrentDate("2024-06-29 20:41:51");

        String password="123456";
        password=SecureUtil.MD5Encode(password);

        String comparePasswd = bo.getCurrentDate() + SLAT + password;

        comparePasswd=SecureUtil.MD5Encode(comparePasswd);
        System.out.println(comparePasswd);
        bo.setPassword(comparePasswd);
        //String comparePasswd = loginBO.getCurrentDate() + SLAT + loginBO.getPassword();
        //String enComparePasswd = SecureUtil.MD5Encode(comparePasswd);
        //loginBO.setPassword(enComparePasswd);
        password="654321";
        password=SecureUtil.MD5Encode(password);
        bo.setNewPassword(password);

        //loginBO.setNewPassword("654321");

        String msg = JSON.toJSONString(bo);
        String key = "a05ef585b9a04e70b12d9c0ee6a1c782";
        String mwMsg = SecureUtil.encryptAES(msg, key);
        httpPost.setEntity(new StringEntity(mwMsg, StandardCharsets.UTF_8));

        //String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwMDc0MTQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4Mzk4OTQxNH0._LYWBPBqfBYYpDuJ4d1HQK6dAvavkuLLUhT4sSBeBCc";
        //httpPost.setHeader("Content-Type", "application/text;charset=utf8");
//        httpPost.setHeader("Authorization",token);
        httpPost.setHeader("Authorization", token);
        httpPost.setHeader("Content-type", "application/json");


        //httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        response1 = httpclient.execute(httpPost);
        System.out.println("response1" + response1);

        HttpEntity entity = response1.getEntity();
        if (entity != null) {
            //按指定编码转换结果实体为String类型
            String body = EntityUtils.toString(entity, "UTF-8");
            JSONObject json1 = JSON.parseObject(body);

            System.out.println(body);
            mwMsg = SecureUtil.decryptAES(json1.getString("data"), key);
            System.out.println(mwMsg);


        }
    }


    @Test
    public void get_menu() throws Exception {
        CloseableHttpResponse response1 = null;
        CloseableHttpClient httpclient = HttpClients.createDefault();


        //String url="http://localhost:9200/api/setAES";

        String url = "http://localhost:8005/service-msm/api/getMenu";
        //String url="http://localhost:8090/QianchengAPI/API/SendToSpdb/ordLndStQry";
        JSONObject object = new JSONObject();


        HttpPost httpPost = new HttpPost(url);
        String path = "/key/token.txt";
        Resource resource = new ClassPathResource(path);
        String token =FileUtils.readFileToString(new File(resource.getURI()), Charset.defaultCharset());
        String msg = "{\"user\":\"\",\"name\":\"\",\"flag\":1,\"dataAuthority\":\"\",\"roleId\":\"\",\"pageSize\":9,\"pageIndex\":0}";
        String key = "a05ef585b9a04e70b12d9c0ee6a1c782";
        String mwMsg = SecureUtil.encryptAES(msg, key);
        httpPost.setEntity(new StringEntity(mwMsg, StandardCharsets.UTF_8));

        //String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwMDc0MTQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4Mzk4OTQxNH0._LYWBPBqfBYYpDuJ4d1HQK6dAvavkuLLUhT4sSBeBCc";
        //httpPost.setHeader("Content-Type", "application/text;charset=utf8");
//        httpPost.setHeader("Authorization",token);
        httpPost.setHeader("Authorization", token);
        httpPost.setHeader("Content-type", "application/json");


        //httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        response1 = httpclient.execute(httpPost);
        System.out.println("response1" + response1);

        HttpEntity entity = response1.getEntity();
        if (entity != null) {
            //按指定编码转换结果实体为String类型
            String body = EntityUtils.toString(entity, "UTF-8");
            JSONObject json1 = JSON.parseObject(body);

            System.out.println(body);
            mwMsg = SecureUtil.decryptAES(json1.getString("data"), key);
            System.out.println(mwMsg);


        }
    }

        @Test
        public void get_moudle_list() throws Exception {
            CloseableHttpResponse response1 = null;
            CloseableHttpClient httpclient = HttpClients.createDefault();


            //String url="http://localhost:9200/api/setAES";

            String url="http://localhost:8005/service-msm/api/getMenu";
            //String url="http://localhost:8090/QianchengAPI/API/SendToSpdb/ordLndStQry";
            JSONObject object = new JSONObject();



            HttpPost httpPost = new HttpPost(url);
            String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwODU0ODQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4NDA2NzQ4NH0.KNboMJDQ1dzeDzaRpUJ4TPlvcutQjSzvYkhotw09i4U";
            String msg="{\"user\":\"\",\"name\":\"\",\"flag\":1,\"dataAuthority\":\"\",\"roleId\":\"\",\"pageSize\":9,\"pageIndex\":0}";
            String key="f9210027a93d4fc8b90ce8b11ffcd830";
            String mwMsg = SecureUtil.encryptAES(msg, key);
            httpPost.setEntity(new StringEntity(mwMsg, StandardCharsets.UTF_8));

            //String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IkxPSUUiLCJleHAiOjE2ODQwMDc0MTQsInVzZXIiOiJhZG1pbiIsImlhdCI6MTY4Mzk4OTQxNH0._LYWBPBqfBYYpDuJ4d1HQK6dAvavkuLLUhT4sSBeBCc";
            //httpPost.setHeader("Content-Type", "application/text;charset=utf8");
//        httpPost.setHeader("Authorization",token);
            httpPost.setHeader("Authorization",token);
            httpPost.setHeader("Content-type", "application/json");




            //httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
            response1 = httpclient.execute(httpPost);
            System.out.println("response1"+response1);

            HttpEntity entity = response1.getEntity();
            if (entity != null) {
                //按指定编码转换结果实体为String类型
                String body = EntityUtils.toString(entity, "UTF-8");
                JSONObject json1=JSON.parseObject(body);

                System.out.println(body);
                mwMsg = SecureUtil.decryptAES(json1.getString("data"), key);
                System.out.println(mwMsg);


            }


        }



    @Test
    public void RSA1_test() throws Exception {
        String str= UUID.randomUUID().toString().replace("-","");
        System.out.println("公钥加密私钥解密");
        str=str+"/这是一个公钥加密私钥解密的例子";
        System.out.println(str);
        //String publickey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP6njJSAGhC0DFlks0rweSB0pFbeIJ3h/RjeTU\r\nfR/IXXdRuoCEG/q/rUm7nAy5dPCYcFjvy/jlvv0XqoG+m/XIFMbXkmKBsHza2hZGI1Fwb4Vr6liI\r\ngtDxSZi2Yd8YkCtq55qe5CHJHI+eZAZWn/8CmJ6oleiyx01nhfJLB6wclQIDAQAB\r\n";              ;
        String  priPath="a.pub";
        String publickey = FileUtils.readFileToString(new File(priPath), Charset.defaultCharset());

        String resJiami=RsaUtil.encryptRSA(str, publickey);
        System.out.println(resJiami);
//        String privatekey="MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAM/qeMlIAaELQMWWSzSvB5IHSkVt\n" +
//                "4gneH9GN5NR9H8hdd1G6gIQb+r+tSbucDLl08JhwWO/L+OW+/Reqgb6b9cgUxteSYoGwfNraFkYj\n" +
//                "UXBvhWvqWIiC0PFJmLZh3xiQK2rnmp7kIckcj55kBlaf/wKYnqiV6LLHTWeF8ksHrByVAgMBAAEC\n" +
//                "gYAUh3tLrI90nk7T86YTWqDtu0iLGHF0NfmAUHlivcQQnaH1cOvVn4mfuXWJT7w156UF+Dnf240E\n" +
//                "6lnFJ3HOJ0oaPNobhYU7FNUIOpjQFLdo50A3AMVgrpKwNi/rJLczwCF/o/ZGOkPfTJ3zRBKsqxI8\n" +
//                "JYP2UPWuAkm8OaJermVD4QJBAOpaYcChL98yd2dTyu/M4O3djSLAQCCYUOlN8sAXBcklTpER4mnI\n" +
//                "Tn9lsymboZHRVsQsas+urxTyjsrnuNvVgT0CQQDjHvH6E+Y/lR30Pdh3Jd3Fk9eeolA3/q2ODyHr\n" +
//                "qwRdMCI243tg6GQVk/KBqzO9ekC/b1wpDOp/XuauW7LHZQ45AkEAlw9TW1uLBA//r3bvpMsnYawh\n" +
//                "wXiy3U/RN9Gq2+77J8EId7JTg2Q+VRg0+Gj9KIULrMAEyYIMETCYomnjWrCw8QJACB+LOA6OJagH\n" +
//                "sjykCV7pV6+5/op/pAEP5AzWgb9UIKEgGCZ6uzSUn9Dy04B0EUrWFgK9oRo9KOEUDxhohIkwwQJA\n" +
//                "LNBOAh9kJf8jLkWWEd6+5z5SHLIjCAMQi65E2KyjgSr50iMGBdx0ERrwaJ0u/ULiqWtF3q0UHTd2\n" +
//                "rK9NnHO0Pg==";
        priPath="a.pri";
        String privatekey = FileUtils.readFileToString(new File(priPath), Charset.defaultCharset());

        String mwMsg = RsaUtil.decrypt(resJiami, privatekey);
        System.out.println(mwMsg);
//****************************************************
        System.out.println("私钥加密公钥解密");
        str=UUID.randomUUID().toString().replace("-","")+"这是一个私钥加密公钥解密的例子";
        System.out.println("原始文档"+str);

        resJiami=RsaUtil.encryptRSA(str, privatekey,"private");
        mwMsg = RsaUtil.decrypt(resJiami, publickey,"public");
        System.out.println("解密后文档"+mwMsg);



    }
    @Test
    public void userlist(){
//        LoginBO bo=new LoginBO();
//        bo.setUserName("admin");
//        //2023-05-10 23:48:51loie_api25D55AD283AA400AF464C76D713C07AD
//        bo.setLoginDate("2023-05-10 23:48:51");
//        UserListBO userListBO = userListService.getUserInfoByUser(bo.getUserName());
//        //System.out.println(userListBO);
//        if (userListBO != null) {
//            String id = userListBO.getId();
//            String password = userListBO.getPassword();
//            password="qiancheng";
//            password=SecureUtil.MD5Encode(password);
//            System.out.println(password);
//            String comparePasswd = bo.getLoginDate() + SLAT + password;
//            System.out.println(comparePasswd);
//            String enComparePasswd = SecureUtil.MD5Encode(comparePasswd);
//            System.out.println(enComparePasswd);
        Set<String> keys = redisTemplate.keys("*");
        System.out.println(keys);

            //LoginBO(id=null, password=B1040B7A4C3E4B7A3202647AAF57616D, userName=admin, loginDate=2023-05-10 20:30:20, newPassword=null, currentDate=null)
//            if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(password)
//                    && !"1".equals(userListBO.getIsLocked())) {
//                String comparePasswd = bo.getLoginDate() + SLAT + password;
//                String enComparePasswd = SecureUtil.MD5Encode(comparePasswd);
//                System.out.println(enComparePasswd);
////            }
//        }
    }
}
